package com.wang.tx.mysql;

import com.wang.tx.core.Tx;

import java.sql.Connection;
import java.sql.SQLException;

public abstract class MySqlTx extends Tx {

    private Connection connection;

    public MySqlTx(Connection connection) {
        this.connection = connection;
    }

    @Override
    protected void prepare() throws Throwable {
        connection.setAutoCommit(false);
    }

    @Override
    protected void commit() {
        try {
            connection.commit();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void rollback() {
        try {
            connection.rollback();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
